﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Minio.AspNetCore;

namespace Common.Framework.Core.Minio
{
    /// <summary>
    /// minio
    /// </summary>
    public static class MinioConfigure
    {
        /// <summary>
        /// 配置Minio
        /// </summary>
        /// <param name="services"></param>
        /// <param name="Configuration"></param>
        /// <returns></returns>
        public static IServiceCollection ConfigureMinio(this IServiceCollection services, IConfiguration Configuration)
        {
            services.Configure<UrlConfig>(Configuration.GetSection("Url"));

            services.AddMinio(options =>
            {
                options.Endpoint = Configuration["MinioConfig:Endpoint"];  // 这里是在配置文件接口访问域名
                options.Region = Configuration["MinioConfig:Region"];  // 地址
                options.AccessKey = Configuration["MinioConfig:AccessKey"];  // 用户名
                options.SecretKey = Configuration["MinioConfig:SecretKey"];   // 密码
            });

            services.AddSingleton<IMinioService, UrlService>();

            return services;
        }
    }
}
